package com.daodao.daodaoschedule.application.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daodao.daodaoschedule.domain.wechat.WechatAccount;
import com.daodao.daodaoschedule.infrastructure.dao.entity.WechatAccountPO;
import com.daodao.daodaoschedule.infrastructure.dao.mapper.WechatAccountMapper;
import com.daodao.daodaoschedule.infrastructure.repository.WechatAccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author mal
 * @date 2022-09-03 11:57
 */
@Service
public class WechatAccountService {

    @Autowired
    private WechatAccountMapper wechatAccountMapper;

    private WechatAccountRepository wechatAccountRepository;

    public WechatAccountService(WechatAccountRepository wechatAccountRepository) {
        this.wechatAccountRepository = wechatAccountRepository;
    }

    public int save(WechatAccountPO wechatAccountPO) {
        return wechatAccountMapper.insert(wechatAccountPO);
    }


    public List<WechatAccountPO> getAllValid() {
        return wechatAccountMapper.selectList(new QueryWrapper<WechatAccountPO>().lambda().eq(WechatAccountPO::getState, "1"));
    }

    public WechatAccount getByAccountId(Long accountId) {
        return wechatAccountRepository.getByAccountId(accountId);
    }

    public void updateAccount(WechatAccount wechatAccount) {
        wechatAccountRepository.updateAccount(wechatAccount);

    }
}
